﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using _1Dot9MasterData;

namespace _1Dot9MasterDac
{
    public class AdminDac : MasterDacBase
    {
        /// <summary>
        /// 생성자 DB 연결 코드
        /// </summary>
        public AdminDac()
        {
            this.ConnectionStrings = "thiagoms";
        }

        public AdminDac(string _connectionStrings)
        {
            this.ConnectionStrings = _connectionStrings;
        }

        #region Admin 유저 조회
        /// <summary>
        /// Admin 유저 조회
        /// </summary>
        public DataSet AdminUserSelect(Hashtable htParams)
        {
            DbCommand dbCommand = this.DbAccess.GetStoredProcCommand("dbo.UP_AdminUser_Select");

            SetParameter(htParams, dbCommand);

            return this.DbAccess.ExecuteDataSet(dbCommand);
        }
        #endregion

        #region Admin 유저 등록
        /// <summary>
        /// Admin 유저 등록
        /// </summary>
        public int AdminUserInsert(Hashtable htParams)
        {
            DbCommand dbCommand = this.DbAccess.GetStoredProcCommand("dbo.UP_AdminUser_Insert");

            SetParameter(htParams, dbCommand);

            return this.DbAccess.ExecuteNonQuery(dbCommand);
        }
        #endregion

        #region Admin 유저 정보 수정
        /// <summary>
        /// Admin 유저 정보 수정
        /// </summary>
        public int AdminUserInfoUpdate(Hashtable htParams)
        {
            DbCommand dbCommand = this.DbAccess.GetStoredProcCommand("dbo.UP_AdminUser_Info_Update");

            SetParameter(htParams, dbCommand);

            return this.DbAccess.ExecuteNonQuery(dbCommand);
        }
        #endregion

        #region Admin 유저 비밀번호 수정
        /// <summary>
        /// Admin 유저 정보 수정
        /// </summary>
        public int AdminUserPwUpdate(Hashtable htParams)
        {
            DbCommand dbCommand = this.DbAccess.GetStoredProcCommand("dbo.UP_AdminUser_Pw_Update");

            SetParameter(htParams, dbCommand);

            return this.DbAccess.ExecuteNonQuery(dbCommand);
        }
        #endregion

        #region 파라미터 셋팅
        private void SetParameter(Hashtable htParams, DbCommand dbCommand)
        {
            if (htParams != null)
            {
                foreach (string strKey in htParams.Keys)
                {
                    if (htParams[strKey] == null) continue;
                    this.DbAccess.AddInParameter(dbCommand, strKey, TypeAlias.GetDbType(htParams[strKey].GetType()), htParams[strKey]);
                }
            }
        }
        #endregion
    }
}
